package com.example.rlw.mvpplugintest.app;

import android.app.Application;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.hardware.Camera;

import com.example.rlw.mvpplugintest.prompt.DefaultCallback;
import com.example.rlw.mvpplugintest.prompt.EmptyCallback;
import com.example.rlw.mvpplugintest.prompt.ErrorCallback;
import com.example.rlw.mvpplugintest.prompt.LoadingCallback;
import com.example.rlw.mvpplugintest.prompt.TimeoutCallback;
import com.kingja.loadsir.callback.HintCallback;
import com.kingja.loadsir.core.LoadSir;
import com.orhanobut.logger.AndroidLogAdapter;
import com.orhanobut.logger.BuildConfig;
import com.orhanobut.logger.Logger;

/**
 * Created by rlw on 2018/10/12.
 */

public class MyApp extends Application {
    public static Context mContext;

    @Override
    public void onCreate() {
        super.onCreate();

        if (isApkInDebug()) {
            //测试时打印日志
            Logger.addLogAdapter(new AndroidLogAdapter());
        } else {
            //发布版不打印日志
            Logger.addLogAdapter(new AndroidLogAdapter() {
                @Override
                public boolean isLoggable(int priority, String tag) {
                    return BuildConfig.DEBUG;
                }
            });
        }

        //统一处理布局
        LoadSir.beginBuilder()
                .addCallback(new ErrorCallback())
                .addCallback(new EmptyCallback())
                .addCallback(new TimeoutCallback())
                .addCallback(new LoadingCallback())
                .addCallback(new DefaultCallback())
                .setDefaultCallback(DefaultCallback.class)
                .commit();

        mContext = getApplicationContext();
    }

    /**
     * 判断当前版本是 debug 版 还是 release 版
     *
     * @return
     */
    public boolean isApkInDebug() {
        try {
            ApplicationInfo info = getApplicationInfo();
            return (info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
        } catch (Exception e) {
            return false;
        }
    }
}
